//获取url中的参数
function getUrlParam(key) {
    var reg = new RegExp("(^|&)"+key+"=([^&]*)(&|$)");
    var result = window.location.search.substr(1).match(reg);
    return result?decodeURIComponent(result[2]):null;
}
$(function() {
    var wdwWth = $(window).width(); var wdwHht = $(window).height();
    var unInstruct = getUrlParam("unInstruct");
    if (unInstruct) {
        $('#status').hide().val(1);
        $('#status-label').hide();
    }

    $('#dg').datagrid({
        url: '/mail/nopsListJson.ajx',
        method: 'post',
        queryParams: {
            status: $('#status').val(),
            number: $('#number').val(),
            source: $('#source').val(),
            deptNo: getUrlParam('deptNo') || $('#deptNo').val() || null
        },
        pagination: true,
        nowrap: true,
        striped: true,
        pagePosition:'bottom',
        fitColumns: true,
        iconCls:'icon-qxtab',
        width:wdwWth-20,
        // height:wdwHht-10,
        singleSelect: false,
        selectOnCheck:false,
        checkOnSelect:false,
        toolbar: '#toolbars',
        pageSize:20,
        pageList: [10,20,50,100],
        columns:[[
            {field: 'swiftNumber', title: '流水号'},
            {field:'summary',title:'摘要'},
            {field:'authorName',title:'来信人'},
            {field:'address',title:'地址', formatter: function(value) { return value && value !== 'null' ? value : ''; }},
            {field:'source',title:'来源'},
            {field:'sentAt', title: '发送日期', formatter: function(value) {
                return value && moment(value).isValid() ? moment(value).format('YYYY-MM-DD') : '';
            }},
            {field:'instructAt',title:'日期', formatter: function(value) { return value && moment(value).isValid() ? moment(value).format('YYYY-MM-DD') : '';}},
            {field:'instructor',title:'批示人'},
            {field:'null',title:'操作', formatter: function(value,rowData,rowIndex) { return '<a href="javascript:void(0);" onclick="showDetailWin('+rowData.id+')">详情</a>';}}
        ]]
    });
    $('#search').click(function() {
        var status = $('#status').val();
        var number = $('#number').val();
        var source = $('#source').val();
        var deptNo = getUrlParam('deptNo') || $('#deptNo').val() || null;
        $('#dg').datagrid('load', {deptNo: deptNo, status: status, number: number, source: source});
    });
});